package com.example.zsfinacialmanage.activity;
import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.example.zsfinacialmanage.R;
import com.example.zsfinacialmanage.adapter.OutpayAdapter;
import com.example.zsfinacialmanage.bean.OutpayBean;
import com.example.zsfinacialmanage.db.MyDBHelper;
import java.util.ArrayList;
import java.util.List;
public class PayDetailActivity extends AppCompatActivity {
    RecyclerView recy_View;
    MyDBHelper mhelper;
    SQLiteDatabase db;
    List<OutpayBean> arr1 = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_detail);
        initView();
        initData();
        OutpayAdapter adapter = new OutpayAdapter(PayDetailActivity.this, arr1);
        StaggeredGridLayoutManager st = new StaggeredGridLayoutManager(StaggeredGridLayoutManager.VERTICAL, 1);
        recy_View.setLayoutManager(st);
        recy_View.setAdapter(adapter);
    }
    private void initView() {
        recy_View = findViewById(R.id.recy_view_outdetail);
        mhelper = new MyDBHelper(PayDetailActivity.this);
        db = mhelper.getWritableDatabase();
    }
    private void initData() {
        Cursor cursor = db.rawQuery("select * from pay_out", null);
        while (cursor.moveToNext()) {
            @SuppressLint("Range")int myid = cursor.getInt(cursor.getColumnIndex("id"));
            @SuppressLint("Range")double outmoney = cursor.getDouble(cursor.getColumnIndex("outmoney"));
            @SuppressLint("Range")String outtime = cursor.getString(cursor.getColumnIndex("outtime"));
            @SuppressLint("Range")String outtype = cursor.getString(cursor.getColumnIndex("outtype"));
            @SuppressLint("Range")String outpayee = cursor.getString(cursor.getColumnIndex("outpayee"));
            @SuppressLint("Range")String outremark = cursor.getString(cursor.getColumnIndex("outremark"));
            OutpayBean outpayBean = new OutpayBean(myid, outmoney, outtime, outtype,outpayee,outremark);
            arr1.add(outpayBean);
        }
    }
}